<?php

use Cartalyst\Sentry\Users\Eloquent\User as SentryUserModel;
use Illuminate\Database\Eloquent\SoftDeletingTrait;

class User extends SentryUserModel {

	protected $table = 'w_users';
	
	use SoftDeletingTrait;
 
	/**
	 * Returns the user full name, it simply concatenates
	 * the user first and last name.
	 *
	 * @return string
	 */
	public function fullName()
	{
		return "{$this->first_name} {$this->last_name}";
	}

	/**
	 * Returns the user Gravatar image url.
	 *
	 * @return string
	 */
	public function gravatar()
	{
		// Generate the Gravatar hash
		$gravatar = md5(strtolower(trim($this->gravatar)));

		// Return the Gravatar url
		return "//gravatar.org/avatar/{$gravatar}";
	}

	public function isOwnedCar($car=null)
	{
		if ($this->hasAnyAccess(array('admin', 'operator'))){
			return true;
		}
		if ($car && $this->hasAccess('customer')) {
			if (isset($car->customer_id)) {
				return $car->customer_id == $this->customer_id;
			}
		}
		return false;
	}
}
